<?php
if ($_SERVER['PHP_SELF'] == __FILE__) { header("HTTP/1.0 404 Not Found"); die(); }
/*
if(isset($url['k']) && isnum($url['k']) && $url['k'] > 0) $kid = (int) $url['k']; else $kid = 0;
if(isset($url['m']) && isnum($url['m']) && $url['m'] > 0) $mid = (int) $url['m']; else $mid = 0;
if (isset($url['p']) && isnum($url['p']) && $url['p'] > 0) $p = (int) $url['p']; else $p = 0;

if ($conf['Palaikymas'] == 0) klaida("Remontas",$conf['Maintenance'], "Svetainė uždaryta");

//
// Pirminis psl.
//
if ($kid > 0) { $keshas = "naujienos_$kid"; } else { $keshas = "naujienos_p$p"; }
if ($kid == 0) {

	$result = $cache->get('content', $keshas);
	if ($result != false && !ADMIN) {
		echo $result;
	}
	else {
		ob_start();

		$limit = $conf['News_limit'];
		$viso = kiek(LENTELES_PRIESAGA."naujienos");
		$text = '';

		echo "
			<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
				<tr>
					<td valign='top' style=\"width: 49.5%;\">";
		$sql = $db->uzklausa("SELECT SQL_CACHE `id`,`tid`,`pav` FROM `".LENTELES_PRIESAGA."d_straipsniai` ORDER BY `last_data` DESC LIMIT 0,5");
		while ($row = $db->masyvas($sql)) {
			$text .= "<a href='?id,25;t," . $row['tid'] .";s," . $row['id'] ."'>" . $row['pav'] ."</a><br/>";
		}
		echo lentele("Naujausi Forumo pranešimai",$text);
		$text = '';
		echo "
				</td>
				<td valign='top' style=\"width: 1%;\"></td>
				<td valign='top' style=\"width: 49.5%;\">";

		$sql = $db->uzklausa("SELECT SQL_CACHE `id`,`pid`,`pav` FROM `".LENTELES_PRIESAGA."straipsniai` WHERE `rodoma`='TAIP' ORDER BY `id` DESC LIMIT 0,5");
		while ($row = $db->masyvas($sql)) {
			$text .= "<a href='?id,22;p," . $row['pid'] .";t," . $row['id'] ."'>" . $row['pav'] ."</a><br/>";
		}
		echo lentele("Naujausi Straipsniai",$text);
		unset($text,$sql);

		echo "
				</td>
				</tr>
			</table>\n<br />";	

		$sql = $db->uzklausa("SELECT SQL_CACHE `id`, `pavadinimas`, `naujiena`, `data`, `autorius`, `kom`,
		(SELECT COUNT(*) AS `kiek` FROM `".LENTELES_PRIESAGA."kom` WHERE `pid`='50' AND `".LENTELES_PRIESAGA."kom`.`kid` = `".LENTELES_PRIESAGA."naujienos`.`id`) AS `viso`
		FROM `".LENTELES_PRIESAGA."naujienos` ORDER BY `data` DESC LIMIT $p,$limit");
		while ($row = $db->masyvas($sql)) {
			if($row['kom'] == "taip") {
				$komentarai = "<div class=\"sarasas\" style=\"text-align: right\"><a href=\"?id,50;k,".$row['id']."\">Komentarai (" . $row['viso'] .")</a></div>";
			}
			else {
				$komentarai = "<div class=\"sarasas\" style=\"text-align: right\"></div>";
			}
			echo lentele($row['pavadinimas'] . " (autorius: ".$row['autorius'].")", $row['naujiena']." " . $komentarai);
		}

		if ($viso >= $limit) { echo puslapiai($p,$limit,$viso,10); }

		$result = ob_get_contents(); ob_end_clean();
		if (!ADMIN) $cache->set('content', $keshas, $result); echo $result;

	}

}
else {
	//
	// Komentarai
	//
	$result = $cache->get('content', $keshas);
	if ($result != false && !ADMIN) {
		echo $result;
	}
	else {
		ob_start();

		$sql = $db->masyvas($db->uzklausa("SELECT SQL_CACHE * FROM `".LENTELES_PRIESAGA."naujienos` WHERE `id`='".(int) $kid."'"));
		if ($sql['kom'] == 'taip') {
			echo lentele($sql['pavadinimas'], $sql['naujiena']);
			if (!empty($sql['daugiau'])) { echo lentele("Plačiau", $sql['daugiau']); }
			$result = ob_get_contents(); ob_end_clean(); 
			if (!ADMIN) $cache->set('content', $keshas, $result); echo $result;
			//Rodom komentarus
			require("priedai/komentarai.php");
			komentarai($kid);
		}
		else {
			klaida("Klaida","Tokios naujienos nėra arba ji buvo ištrinta"); redirect("?id,50","meta");
		}

	}
}
// Išvalom cache
// if (isset($_POST['n_kom']) && !empty($_POST['n_kom']) && $_POST['Naujas'] == 'Siųsti' || (isset($url['dk']) && $url['dk'] > 0)) $cache->remove("content", $keshas);
*/
?>
